<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.commons.Constants"%>

<chiptrack:checkLogon sourcePage="/priceSetting.do"/>

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<SCRIPT language="JavaScript">
    var m = 0;
    var n = new Array( 4 );
    function GetAllProducts()
    {
        newWindow = window.open('loadProducts.do','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=500,height=600,left=300,top=30,resizable=no');
  	    newWindow.focus();
    }
    function updatePrices()
    {
		var temp = document.priceForm;
		var pa = document.getElementById ("errors");
        pa.innerHTML = "";
        var message ='';
        xyz:
        for( var i = 0 ; i <= m ; i ++ )
        {
            for( var j = 0; j <= n[i] ; j++ )
            {
                fromQty = document.priceForm['periodList['+i+'].priceList['+j+'].fromQty'];
                toQty   = document.priceForm['periodList['+i+'].priceList['+j+'].toQty'];

                if ( fromQty.value != null && toQty.value != null && fromQty.value != '' && toQty.value != '' )
                {
                    // TO CHECK FOR VALID INTEGERS
                    if( checkInteger( fromQty.value , "From Quantity" ,"N")  == false)
                    {
                        fromQty.focus();
                        message = errMsg;
                        break xyz;
                    }
                    if( checkInteger( toQty.value , "To Quantity" ,"N")  == false )
                    {
                        toQty.focus();
                        message = errMsg;
                        break xyz;
                    }

                    // TO CHECK WETHER FROM QTY GREATER THEN TO QTY
                    if ( parseInt(fromQty.value ) >= parseInt(toQty.value) )
                    {
                        message = "'To quantity 'cannot be less then or equal to' From quantity'";
                        toQty.focus();
                        break xyz;
                    }
                }
                else
                {
                    if( fromQty.value != '' )
                    {
                        message = "To Quantity must be given if From quantity is given";
                        toQty.focus();
                        break xyz;
                    }

                    if( toQty.value != '' )
                    {
                        message = "From Quantity must be given if To quantity is given";
                        fromQty.focus();
                        break xyz;
                    }
                }
            }
        }
        if( message != ''  )
		{
			pa.innerHTML = '<li>'+message;
			return;
		}
        xyz1:
        for( var i = 0; i <= m; i++ )
        {
            for( var j = 0; j < n[i]; j++ )
            {
                for( var k = j + 1; k <= n[i]; k++ )
                {
                    fromQty  = document.priceForm['periodList['+i+'].priceList['+j+'].fromQty'];
                    toQty    = document.priceForm['periodList['+i+'].priceList['+j+'].toQty'];

                    fromQty1 = document.priceForm['periodList['+i+'].priceList['+k+'].fromQty'];
                    toQty1   = document.priceForm['periodList['+i+'].priceList['+k+'].toQty'];

                    if ( fromQty.value != null && toQty.value != null && fromQty.value != '' && toQty.value != '' &&
                         fromQty1.value != null && toQty1.value != null && fromQty1.value != '' && toQty1.value != '' )
                    {
                        if ( ! ( parseInt(fromQty.value) > parseInt(toQty1.value) || parseInt(toQty.value) < parseInt(fromQty1.value ) ))
                        {
                            fromQty1.focus();
                            message = "Please define a valid range";
                            break xyz1;
                        }
                    }
                }
            }
        }
        if( message != ''  )
		{
			pa.innerHTML = '<li>'+message;
			return;
		}
        document.priceForm.action.value = "UpdateQuarterPricing";
        document.priceForm.submit();
    }

    function loadPrice()
    {
        var pa = document.getElementById ("errors");

        if ( document.priceForm.productId.value == '' || document.priceForm.productId.value == '-1' || document.priceForm.productId.value == '0')
        {
            pa.innerHTML = "<li>Please select a product to set the price</li>";
			return;
        }
        var selVal = document.priceForm.productId.selectedIndex;

        document.priceForm.action.value = "loadQuarterPricing";
        document.priceForm.mktpartNo.value = document.priceForm.productId.options[selVal].text;
        document.priceForm.submit();
    }
    function addRow(no)
    {
        document.priceForm.action.value = "addRow";
        document.priceForm.periodNo.value = no;
        document.priceForm.submit();
    }
    if (document.layers)
        window.setResizable(false);

    function showErrorReportPage()
    {
        newWindow = window.open ('<%=chipTracContext%>/reportProblem.do','reportProblem','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=750,height=400,resizable=no');
        newWindow.focus();
    }
    function restrictCharecters()
    {
        if( event.keyCode < 48 || event.keyCode > 57 )
        {
            event.keyCode = false;
        }
    }

</SCRIPT>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>

<!-- Top Header Start-->

<%@ include file="/jsp/includes/header.jsp" %>

<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->

<%@ include file="/jsp/marketing/price_setting_menu.jsp" %>

</TD>
<!-- end of the side navigations -->
<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>
<!-- from here your body starts -->

<center><span class="NArialW">Quarter Pricing</span></center>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10>
<html:form name="priceForm" action="/priceSetting.do" method="post" type="com.scalar.chiptrack.marketing.PricingForm" scope="session">
<table border="0" width="85%" align=right>
     <logic:equal name="showMessage" value="TRUE">
        <tr><td colspan="3" align='left'><font class='NArialS'color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b></font></td></tr>
    </logic:equal>
    <tr><td colspan='3'><font class="NArialL"><font color="FF0000"><FONT id="errors"></FONT></FONT></FONT></TD></TR>
    <tr><td colspan='3' align="left"><chiptrack:errors styleClass="NArialL" /></td></tr>
    <tr><td colspan='3' align="left"><chiptrack:info styleClass="NArialL" /></td></tr>
    <logic:equal name="showList" value="FALSE">

    <tr>
      <td width="15%">&nbsp;</td>
      <td class='NArialL' width="25%"><font class="NArialL">Product Name :<font size="-2"> <br>(<bean:message key="label.mfgPartNumber" />)</font></td>
      <td>
      <font class="NArialL" width="60%">
      	<html:select  property="productId" styleClass="txfield">
			<html:option value="-1">--Select Product Name--</html:option>
			<html:options collection="mktgParts" property="value" labelProperty="label"/>
	    </html:select>
      	</td>
      <tr>
          <td width="15%">&nbsp;</td>
          <td  class="NArialL" width="25%">Sales Order Type :</td>
      	  <td class="NArialL" width="60%">
            <html:select  property="sample" styleClass="txfield">
                <html:option value="1">Regular</html:option>
                <html:option value="0">Sample</html:option>
            </html:select>
          </td>
    </tr>
    <tr><td colspan=3><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>

        <tr><td colspan=3 align="center">
            <a href="javascript:loadPrice();"><img src="<%=chipTracContext%>/jsp/includes/images/search.gif" border=0 onmouseover="window.status='Click to Search for Prices';return true" onmouseout="window.status='';return true"title="Click here to Search for prices"></a>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="javascript:document.priceForm.reset();"><img src="<%=chipTracContext%>/jsp/includes/images/reset.gif" border=0 onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true"title="Click here to Reset"></a>
        </td></tr>
    </logic:equal>
    <logic:equal name="showList" value="TRUE">

    <tr>
        <td colspan='2' align="left" class='NArialL'>Price setting for marketing part # <font color="blue"><%= request.getParameter("mktpartNo")%></font></td>
     </tr>
    <logic:equal value="0" name="priceForm" property="sample" >
        <tr><td colspan='3' align="left" class='NArialL'>For  <font color="blue"> Sample </font> Sales Order   </td></tr>
     </logic:equal>
    <logic:equal value="1" name="priceForm" property="sample">
        <tr><td colspan='3' align="left" class='NArialL'>For  <font color="blue"> Regular </font> Sales Order   </td></tr>
    </logic:equal>
    <html:hidden name="priceForm" property="productId" />
    <html:hidden name="priceForm" property="sample" />
    <tr>
        <td width='60%' class="NArialL" colspan='2' align="center" bgcolor="#993333">
                <font color="#FFFFFF">Quantities</font></td>
        <td width='30%' class="NArialL" rowspan='2' align="center" bgcolor="#993333"><font color="#FFFFFF">Price</font></td>
    </tr>
    <tr>
        <td width='30%' class="NArialL" align="center" bgcolor="#993333"><font color="#FFFFFF"> From </font></td>
        <td width='30%' class="NArialL" align="center" bgcolor="#993333"><font color="#FFFFFF"> To </font></td>
        <td width='30%'></td>
     </tr>

        <nested:iterate name="PricingForm" property="periodList" indexId="periodNo">
                <tr>
                    <td width='30%' class="NArialL"> <nested:write  property="quarter" /> </td>
                    <td width='30%' class="NArialL"> <nested:write  property="startDate" /> </td>
                    <td width='30%' class="NArialL"> <nested:write  property="endDate" /></td>
                </tr>
                <nested:iterate property="priceList" indexId="priceListNo" >
                    <tr>
                        <td width='30%' class="NArialL"> <nested:text property="fromQty" styleClass="valuetxfield" onkeypress="javascript:restrictCharecters()" /> </td>
                        <td width='30%' class="NArialL"> <nested:text property="toQty" styleClass="valuetxfield" onkeypress="javascript:restrictCharecters()" /> </td>
                        <td width='30%' class="NArialL"> <nested:text  property="price" styleClass="valuetxfield" maxlength="9" onkeypress="javascript:restrictCharacters(this,7,2)" onkeyup="javascript:restrictAmt(this,7,2)"  /></td>
                        <script>
                            m = '<bean:write name="periodNo"/>';
                            n[<bean:write name="periodNo"/>] = '<bean:write name="priceListNo"/>';
                        </script>


                    </tr>
                </nested:iterate>
                <tr><td colspan=3><a href="javascript:addRow(<bean:write name="periodNo"/>)"><IMG src='<%=chipTracContext%>/jsp/includes/images/addmore.gif' border=0 onmouseover="window.status='Click to Add More Text Boxes';return true" onmouseout="window.status='';return true"title="Click here to Add More Text Boxes"></a></td></tr>

        </nested:iterate>


    <tr><td colspan=3><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>


    <tr><td colspan=3><FONT id="font1"></FONT></TD></TR>

    <tr><td colspan=3><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
    <tr>
      <td colspan=2 align=center>
        <chiptrack:restrictedLink functionality='<%=Functionality.MARKETING_QUARTER_PRICING %>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:updatePrices();' onmouseover="window.status='Click to Update Prices';return true" onmouseout="window.status='';return true">
            <img border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" title="Click here to Update Prices"/>
        </chiptrack:restrictedLink>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <a href="javascript:document.priceForm.reset();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"  onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true"title="Click here to Reset"></a>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <a href="<%=chipTracContext%>/priceSetting.do?action=quarterPricing"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" width="53" height="17"  onmouseover="window.status='Click to Cancel ';return true" onmouseout="window.status='';return true"title="Click here to Cancel"></a>
        </td>
    </tr>
    </logic:equal>

  </table>
<input type="hidden" name="action" value="">
<input type="hidden" name="periodNo" value="">
<input type="hidden" name= "mktpartNo" value ="<%=request.getParameter("mktpartNo")%>">
</html:form>
<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>
<!-- Footer starts here -->

<%@ include file="/jsp/includes/footer.jsp" %>

<!-- footer end here -->

</BODY>
</HTML>
